<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <script type="text/javascript" src="http://47.94.91.67:10100/web-apps/apps/api/documents/api.js"></script>
    <style>
        body {
            width: 100%;
            height: 90vh;
            display: flex;
            flex-direction: column;
        }
        
        #placeholder {
            width: 100%;
            height: 100vh;
        }
    </style>
</head>

<body>
    <button class="" onclick="callCommand()">callCommand</button>
    <input id="input_text" class="ignore_mouse_evt dd ee ff" type="text" value="字段动态绑定" />
    <div id="placeholder" class="nav" style="width: 100%; height: 100vh;"></div>

</body>
<script>
    function getUuid() {
      return "xxxxxxxxxxxxxxxxxxxxxx".replace(/[xy]/g, function (c) {
        var r = (Math.random() * 16) | 0,
          v = c == "x" ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      });
    }

    function callCommand() {
        Asc.scope = {
            a:1
        };
        connector.callCommand(function() {
            var oDocument = Api.GetDocument();
            var oRange = oDocument.GetRangeBySelect();
            if(!oRange){
                return;
            }
            oRange.AddText("插入文字");
            oRange.SetHighlight('yellow');
        }, function(data) { console.log("callback command");});
    }

    var onDocumentReady = function () {
        console.log("文档准备好了");
        window.connector = docEditor.createConnector();
    };


    var config = {
        "documentType": "word",
        "historyList": {
            "history": [],
            "currentVersion": "1"
        },
        "document": {
            "title": "【经营】通用合同模板.docx",
            "url": "http://47.94.91.67/demo_file/BookmarkForm.docx",
            "permissions": {
                "print": false,
                "download": true
            },
            "attachId": "e932e7bb1e4d449aa9a7d8b403b4b517",
            "fileType": "docx",
            "key": getUuid()
        },
        "editorConfig": {
            "customization": {
                "autosave": false,
                "compactToolbar": true,
                "forcesave": true,
                "toolbarNoTabs": true,
                "help": false,
                "compactHeader": true,
                "hideRightMenu": true,
            },
            "mode": "edit",
            "callbackUrl": "https://api.docs.onlyoffice.com/dummyCallback",
            "lang": "zh-CN",
            "user": {
                "name": "曹瑞剑雄",
                "id": "103"
            }
        }
    };


    var docEditor;
    initDocEditor();
    

    /**
     * 初始化编辑器
     */
    function initDocEditor() {
        // 初始化配置
        config['events'] = {
            onDocumentReady: onDocumentReady
        };
        // config.editorConfig.customization.autosave = false;
        // config.editorConfig.customization.forcesave = true;
        docEditor = new DocsAPI.DocEditor("placeholder", config);
    }


</script>

</html>